﻿using System.Collections.Generic;
using System.Windows;
using Models;

namespace SuperQuery
{
    /// <summary>
    /// Interaction logic for RemoveDatabases.xaml
    /// </summary>
    public partial class RemoveDatabases : Window, Views.IRemoveDatabasesView
    {
        /// <summary>
        /// Initialise the RemoveDatabases window
        /// </summary>
        /// <param name="parentQueryTab">The parent query tab that lauched the Remove Databases window</param>
        public RemoveDatabases(Views.IQueryView parentQueryTab)
            : this()
        {
            // Hook up the data context so that data bining will work
            DataContext = this;

            m_Presenter = new Presenters.RemoveDatabasesPresenter(this, parentQueryTab);
        }

        /// <summary>
        /// Initialise the Remove Databases window
        /// </summary>
        private RemoveDatabases()
        {
            InitializeComponent();
        }

        #region Implementation of IRemoveDatabasesView

        /// <summary>
        /// A list of currently loaded databases
        /// </summary>
        public List<Database> LoadedDatabases
        {
            get
            {
                return (List<Database>)GetValue(LoadedDatabasesProperty);
            }
            set
            {
                SetValue(LoadedDatabasesProperty, value);
            }
        }

        /// <summary>
        /// Using a DependencyProperty as the backing store for LoadedDatabases.  This enables animation, styling, binding, etc...
        /// </summary>
        private static readonly DependencyProperty LoadedDatabasesProperty =
            DependencyProperty.Register("LoadedDatabases", typeof(List<Database>), typeof(RemoveDatabases),
                                        new UIPropertyMetadata(null));

        #endregion

        /// <summary>
        /// Remove selected databases from the parent tabs database list and close the dialog
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            m_Presenter.RemoveDatabasesFromList();
            Close();
        }

        /// <summary>
        /// Close the dialog without doing anything
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        /// <summary>
        /// Select None of the displayed databases
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void btnSelectNone_Click(object sender, RoutedEventArgs e)
        {
            m_Presenter.SelectNone();
        }

        /// <summary>
        /// Select All of the displayed databases
        /// </summary>
        /// <param name="sender">Who raised the event</param>
        /// <param name="e">Details about the event</param>
        private void btnSelectAll_Click(object sender, RoutedEventArgs e)
        {
            m_Presenter.SelectAll();
        }

        /// <summary>
        /// The presenter for this window
        /// </summary>
        private Presenters.RemoveDatabasesPresenter m_Presenter;
    }
}
